using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spinning.Spinning.Entity;
using Spinning.Spinning.Interface;
using Microsoft.Xna.Framework;
using Spinning.Spinning.Unitity;

namespace Spinning.Spinning.Scenes.ProcessScene.TabLayouts
{
    class Tab : AnimationSprite, ITouchable
    {
        TabLayoutScene tabLayout;
        bool isSelect;
        public BaseScene ContainScene { get; set; }


        public bool IsSelect
        {
            get
            {
                return isSelect;
            }
            set
            {
                isSelect = value;
                if (isSelect)
                {
                    SetChangeFrameAnimation(new int[] { 1 });
                }
                else
                {
                    SetChangeFrameAnimation(new int[] { 0 });
                }
            }
        }

        public Tab(TabLayoutScene tl)
        {
            tabLayout = tl;
            Origin = new Vector2(.5f);
        }

        public override void OnLoad()
        {
            base.OnLoad();
            ZIndex = Constants.ui;
            SetAnimation(new Point(1, 2));
            IsSelect = false;
        }

        protected override void UpdateSelf(GameTime gameTime)
        {
            base.UpdateSelf(gameTime);
            if (ContainScene != null)
                ContainScene.Visable = IsSelect;
        }

        public bool Contain(Microsoft.Xna.Framework.Vector2 position)
        {
            position = Vector2.Transform(position, UnProjection);
            Vector2 topLeft = Position - Origin * new Vector2(_texture.Width, _texture.Height) * Scale;
            Vector2 rightDown = topLeft + new Vector2(_texture.Width, _texture.Height) * Scale;
            bool h = (position.X > topLeft.X && position.X < rightDown.X && position.Y > topLeft.Y && position.Y < rightDown.Y);
            return h;
        }

        public void OnTouch(Microsoft.Xna.Framework.Input.Touch.TouchLocation touchLocation)
        {
            tabLayout.OnTabTouch(this);
        }

        public void OnRelease(Microsoft.Xna.Framework.Input.Touch.TouchLocation touchLocation)
        {

        }

        public void OnHold(Microsoft.Xna.Framework.Input.Touch.TouchLocation touchLocation)
        {
            tabLayout.OnTabTouch(this);
        }
    }
}
